const express = require("express")
const server = express()
const expressJWT = require('express-jwt')

const cors = require("cors")
server.use(cors())
const secretKey = "yangzhitao ^_^"  //密钥
server.use(expressJWT({ secret: secretKey }).unless({ path: [/^\/public\//] }))
const multer = require("multer")
server.use(multer().any())
server.use("/public", require("./modules/public"))
server.use("/private", require("./modules/private"))
server.use("/public", express.static("./public"))




server.listen(8080, () => {console.log("open server ! http://127.0.0.1:8080")})


server.use((err, req, res, next) => {
    if (err.name === 'UnauthorizedError') {
        return res.send({ status: 401, message: '登陆超时,请重新登录' })
    }
    res.send({ status: 500, message: '未知错误' })
})